#include "scripts.h"

#include <QApplication>
#include <QProcess>

Scripts::Scripts()
{

}

QTemporaryFile *Scripts::make_temporaryfile(QString var)
{
    auto tempfile = new QTemporaryFile(qApp);
    tempfile->open();
    tempfile->write(var.toUtf8());
    tempfile->flush();
    tempfile->close();
    return tempfile;
}

QString Scripts::make_tempfile(QString var)
{
    return make_temporaryfile(var)->fileName();
}

QString Scripts::bash_scripts(QString var)
{
    auto file = make_temporaryfile(var);

    QProcess process;
    process.start("bash", QStringList() << file->fileName());
    process.waitForFinished();

    file->deleteLater();
    return process.readAllStandardOutput();
}
